
#include "AbstractGeometryData.hpp"

namespace NSCore {

	AbstractGeometryData::AbstractGeometryData() : 
		AbstractObject() {
		
	}

	AbstractGeometryData::~AbstractGeometryData() {

	}

	int AbstractGeometryData::addGeometryRaw(int id, QList<int>& ids, Sp(vtkPolyData) raw, TopoDS_Shape tp) {

		return 0;
	}
 
	AbstractGeometry* AbstractGeometryData::getGeometryRaw(int id) {
		return nullptr;
	}
	 

	void AbstractGeometryData::clearGeometryRaw() { 
		 m_id_map.clear();
		 m_geoms.clear(); 
		 m_part = nullptr;
		 m_part = Sp(vtkAppendPolyData)::New();
		 //m_part->Update(); 
	}

	QPair<Sp(vtkPolyData), TopoDS_Shape> AbstractGeometryData::getGeometryPart() {
		m_part->Update();

		Sp(vtkPolyData) part_poly = m_part->GetOutput();
		Sp(vtkPolyData) normal_poly = normal_data(part_poly);

		return { normal_poly , m_shape };

	}

	void AbstractGeometryData::setGeometryPart(TopoDS_Shape topo) {
		m_shape = topo;

	}

	Sp(vtkPolyData) AbstractGeometryData::getGeometryEdges() {
		Sp(vtkPolyData) part_poly = getGeometryPart().first;
		vtkNew<vtkFeatureEdges> feature_edges;
		feature_edges->SetInputData(part_poly);
		feature_edges->SetFeatureAngle(30);
		feature_edges->BoundaryEdgesOn();
		feature_edges->FeatureEdgesOn();
		feature_edges->NonManifoldEdgesOn();
		feature_edges->ManifoldEdgesOn();
		feature_edges->Update();

		return feature_edges->GetOutput();
	}

	void AbstractGeometryData::mapId(int key_id, int value_id) {

	}

	void AbstractGeometryData::updateGeometry(TopoDS_Shape tp) {
		
	}


	Sp(vtkPolyData) AbstractGeometryData::normal_data(Sp(vtkPolyData) data) {
		vtkNew<vtkPolyDataNormals> normal;
		normal->SetInputData(data);
		normal->SetFeatureAngle(45);
		normal->ConsistencyOff();
		normal->NonManifoldTraversalOn();
		normal->SplittingOn();
		normal->ComputePointNormalsOn();
		normal->ComputeCellNormalsOn();
		normal->FlipNormalsOff();
		normal->Update();

		return normal->GetOutput();
	}

	int AbstractGeometryData::getId(int cellid) {
		return 0;
	}

	void AbstractGeometryData::setGeoPoints(QList<NSCore::GeoPoint>& points) {
		m_geopoints = points;
	}

	void AbstractGeometryData::getGeoPoints(QList<NSCore::GeoPoint>& points) {
		points = m_geopoints;
	}

	const QList<NSCore::GeoPoint> AbstractGeometryData::getGeoPoints() {
		return m_geopoints;
	}


}
